package com.gxl.butt.DAO.impl;

import com.gxl.butt.DAO.IReportInMouthDAO;
import com.gxl.butt.domain.ReportInMouth;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * Created by GUOXIAOLIN on 2018/7/13.
 */
@Repository
public class ReportInMouthDAOImpl extends HibernateBaseDao<ReportInMouth> implements IReportInMouthDAO {

    @Override
    public List<ReportInMouth> getOne(Long userid, String inmouth) {
        String hql = "from " + ReportInMouth.class.getName() + " do where do.userid = " + userid + " and do.inmouth = '" + inmouth + "'";
        List<ReportInMouth>  reportInMouths = this.getListByHql(hql);
        if (reportInMouths != null && reportInMouths.size() > 0){
            return reportInMouths;
        }
        return null;
    }

    @Override
    public Long saveOne(ReportInMouth reportInMouth) {
        return (Long) this.save(reportInMouth);
    }

    @Override
    public void updateOne(ReportInMouth reportInMouth) {
        this.update(reportInMouth);
    }

    @Override
    public List<ReportInMouth> getList(Long userid, Long sum) {
        String hql = "select TOP " + sum + " from " + ReportInMouth.class.getName() + " do where  do.userid = " + userid + " order by do.id desc";
        List<ReportInMouth>  reportInMouths = this.getListByHql(hql);
        if (reportInMouths != null && reportInMouths.size() > 0){
            return reportInMouths;
        }
        return null;
    }
}
